#include "stdio.h"
#include "stdlib.h"
#include <iostream>
#include <fstream>
#include "LIGHT_TARGET.h"
#include "Headstru.hpp"

using namespace std;
HEAD_DDT   head;

int main()
{
	float* XData = NULL;
	float* YData = NULL;
	float* ZData = NULL;
	float* WData = NULL;
	int count_lights;
	

	char* TargetFileName = (char*)"/root/test_light/bechmark_double_all.DDT";
	char* BoundaryFileName[100];

	BoundaryFileName[0] = (char*)"/root/test_light/water_steel(8mm)_water_V.dat";
	BoundaryFileName[1] = (char*)"/root/test_light/water_steel(4mm)_air_V.dat";
	BoundaryFileName[2] = (char*)"/root/test_light/water_steel(8mm)_water_T.dat";
	BoundaryFileName[3] = (char*)"/root/test_light/water_AL(10mm)_air_T.dat";
	BoundaryFileName[4] = NULL;
	
	float SourceX0 = 0;
	float SourceY0 = 0;
	float SourceZ0 = 5000;

	float SourceRX0 = 0;
	float SourceRY0 = 0;
	float SourceRZ0 = 5000;

	float freq_low = 100;
	float freq_step = 10;
	float freq_high = 10000;
	
	float LaunchCenterFrec = 5000;
	float LaunchPulseWidth = 0.001;
	float ReceiveSigWidth = 0.2;
	float FrecSample = 6 * LaunchCenterFrec;
	
	ifstream   fdp(TargetFileName, ios::binary);
	if (!fdp)  return -1;  
	fdp.read((char*)&head, sizeof(HEAD_DDT));
	
	int data_len = head.nodes + 5;
	XData = (float *)malloc(data_len * 8);
	YData = (float *)malloc(data_len * 8);
    ZData = (float *)malloc(data_len * 8);
	WData = (float *)malloc(data_len * 8);

	
	int ret = LIGHT_target_free_light(TargetFileName, BoundaryFileName,
										SourceX0, SourceY0, SourceZ0, SourceRX0, SourceRY0, SourceRZ0,
										freq_low, freq_step, freq_high,
										LaunchCenterFrec, LaunchPulseWidth,
										ReceiveSigWidth, FrecSample,
										&count_lights, &XData, &YData, &ZData, &WData);
										
	
	printf("#############################  %d  %d\n", ret, count_lights);
	
	for (int i = 0; i < data_len - (5 - count_lights); i++)
	{
		printf("#############################  %f  %f  %f  %f\n", XData[i], YData[i], ZData[i], WData[i]);
	}

	return 0;
}
